package com.fx.service.impl;

import com.fx.mapper.SysUserMapper;
import com.fx.pojo.SysUser;
import com.fx.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String account, String pwd) {

        SysUser user = sysUserMapper.findUserByAccount(account);

        if (user != null) {
            if (user.getPassword().equals(pwd)){
                return user;
            }
        }

        return null;
    }

    /**
     *
     * @param queryRealName
     * @param queryRoleId
     * @param currPage  当前页码
     * @param pageSize
     * @return
     */
    @Override
    public List<SysUser> findList(String queryRealName,
                                  Integer queryRoleId,
                                  Integer currPage,
                                  Integer pageSize) {
        //计算起始索引
        int beginIndex = (currPage - 1) * pageSize;

        return sysUserMapper.findList(queryRealName,queryRoleId,beginIndex,pageSize);
    }

    @Override
    public Integer count(String queryRealName, Integer queryRoleId) {
        return sysUserMapper.count(queryRealName,queryRoleId);
    }

    @Override
    public SysUser findUserByAccount(String account) {

        return sysUserMapper.findUserByAccount(account);
    }

    @Override
    public SysUser findUserById(Integer id) {
        return sysUserMapper.findUserById(id);
    }

    @Override
    public boolean add(SysUser sysUser) {

        return sysUserMapper.add(sysUser)==1;
    }
}
